
// (c) Daniel Llorens - 2017

// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option) any
// later version.

/// @file test-large.C
/// @brief Tests specific to WithStorage.

#include <iostream>
#include <iterator>
#include "ra/operators.H"
#include "ra/io.H"
#include "ra/view-ops.H"
#include "ra/format.H"
#include "ra/test.H"

using std::cout; using std::endl; using std::flush;

int main()
{
    TestRecorder tr;
    tr.section("push_back");
    {
        using int2 = ra::Small<int, 2>;
        std::vector<int2> a;
        a.push_back({1, 2});
        ra::Big<int2, 1> b;
        b.push_back({1, 2});

        int2 check[1] = {{1, 2}};
        tr.test_eq(check, ra::start(a));
        tr.test_eq(check, b);
    }
    tr.section("behavior of forced Fortran array");
    {
        ra::Big<int, 2> a ({2, 3}, {0, 1, 2, 3, 4, 5});
        ra::Big<int, 2> b ({2, 3}, {0, 1, 2, 3, 4, 5});
        auto c = transpose({1, 0}, ra::View<int, 2>({3, 2}, a.data()));
        a.dim = c.dim;
        for (int k=0; k!=c.rank(); ++k) {
            std::cout << "CSTRIDE " << k << " " << c.stride(k) << std::endl;
            std::cout << "CSIZE " << k << " " << c.size(k) << std::endl;
        }
        cout << endl;
        for (int k=0; k!=a.rank(); ++k) {
            std::cout << "ASTRIDE " << k << " " << a.stride(k) << std::endl;
            std::cout << "ASIZE " << k << " " << a.size(k) << std::endl;
        }
        cout << endl;
        c = b;
// FIXME this clobber the strides in a, which is surprising -> WithStorage should behave as View.
        a = b;
        for (int k=0; k!=c.rank(); ++k) {
            std::cout << "CSTRIDE " << k << " " << c.stride(k) << std::endl;
            std::cout << "CSIZE " << k << " " << c.size(k) << std::endl;
        }
        cout << endl;
        for (int k=0; k!=a.rank(); ++k) {
            std::cout << "ASTRIDE " << k << " " << a.stride(k) << std::endl;
            std::cout << "ASIZE " << k << " " << a.size(k) << std::endl;
        }
        cout << endl;
        std::cout << "a: " << a << std::endl;
        std::cout << "b: " << b << std::endl;
        std::cout << "c: " << c << std::endl;
    }
    return tr.summary();
}
